﻿using System;
using System.Linq;


class MostFrequentNumber
{
    static void Main()
    {
        int[] numbers = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };

        int bestElement = int.MinValue;
        int tempElement = int.MaxValue;

        int bestFrequency = 0;
        int tempFrequency = 0;

        Array.Sort(numbers);
        //Console.WriteLine(String.Join(",", numbers));

        foreach (var number in numbers)
        {
            if (number != tempElement)
            {
                tempFrequency = 1;
                tempElement = number;
            }
            else
            {
                tempFrequency++;
            }

            if (tempFrequency > bestFrequency)
            {
                bestFrequency = tempFrequency;
                bestElement = tempElement;
            }

        }

        Console.WriteLine("The most frequent element is: {0} - {1} times.", bestElement, bestFrequency);
    }
}

